package com.sihai.core;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

import org.apache.commons.lang.math.NumberUtils;

/**
 * 保存properties 文件
 */
public class AppSettings {

	public static void load(Properties props) {
		if (props == null) {
			return;
		}

		for (Object key : props.keySet()) {
			properties.put(key, props.get(key));
		}
	}

	public AppSettings(File settingFile) {
		this.settingFile = settingFile;
	}

	private File settingFile;

	public void init() throws FileNotFoundException, IOException {
		properties.load(new FileInputStream(this.settingFile));
	}

	private static Properties properties = new Properties();

	public static String getSetting(String key) {
		return properties.getProperty(key);
	}

	public static Long getLong(String key) {
		return NumberUtils.toLong(getSetting(key), 0);
	}

}
